import { request } from '../../utils/requestUtils';
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    type:{
      type:String,
      value:"1"
    },
    showBtn:{
      type:String,
      value:"1"
    }
  },
  attached: function () {
    this.setData({
      equipmentNameBeforeClose: (action) => this.equipmentNameBeforeCloseHandler(action)
    })
  },

  /**
   * 组件的初始数据
   */
  data: {
    equipmentName:'',//设备名称
    equipmentShow:false,//设备弹窗
    equipmentNameBeforeClose: {}
  },

  /**
   * 组件的方法列表
   */
  methods: {
  //弹出输入框 输入设备号后四位
  getEquipmentShow() {
    this.setData({
      equipmentShow: true,
      equipmentName: ''
    })
  },
    //为设备号赋值
    equipmentNameChange(event) {
      this.setData({
        equipmentName: event.detail
      })
    },
    //弹窗校验
  async equipmentNameBeforeCloseHandler(action) {
    if (action === 'confirm') {
      if (!this.data.equipmentName) {
        return false
      } else {
        const result = await request({
          url: "/api/bus/equipment/endWith4/"+this.properties.type+"/?endWithCode=" + this.data.equipmentName,
          method: "POST",
          data:{
            params:{
              endWithCode:this.data.equipmentName
            }
          }
        })
        console.log('result-->',result)
        if(result.data.code ==200){
          this.triggerEvent('equipmentResult', result.data.data)
          return true
        }else{
          return false
        }
       
      }
    }else{
      return true
    }
  },
  }
})